from geventwebsocket.handler import WebSocketHandler
from geventwebsocket.server import WSGIServer
from geventwebsocket.websocket import WebSocket #语法提示
from flask_script import Manager,Command
from apps import create_app
from flask_migrate import Migrate,MigrateCommand
from flask import jsonify
from ext import db
#全局锁
from threading import RLock

#在Migrate管理之前，要导入各个应用中模型模块
from apps.user.models import *
from apps.resource.models import *

#拿flask应用,传递进去配置
app = create_app()
#应用于数据库用migrate管理
migrate = Migrate(app,db)
manager = Manager(app=app)
manager.add_command('db',MigrateCommand)

all_lock = RLock()


if __name__ == '__main__':
    #1\普通的flask项目，api
    # manager.run()
    #2\使用WSGIServer使用项目支持sse,支持websocket
    server = WSGIServer(('0.0.0.0', 8888), app, handler_class=WebSocketHandler)
    #开启多线程
    # server.threadpool_size = 10
    #启动
    print(server,'.....')
    server.serve_forever()




